package com.swsc.solarverse.common.mybatis;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.swsc.solarverse.common.util.PageUtils;

import java.util.Map;

/**
 * @Author chencl
 * @Date 2022/2/7 14:06
 * @Version 1.0
 * @Description MybatisService
 */
public interface MybatisService<T> extends IService<T> {

    /**
     * mybatis plus page转换通用page
     * @param page
     * @return
     */
    default com.swsc.solarverse.common.model.PageInfo<T> page(com.swsc.solarverse.common.model.PageInfo<Object> page){
        IPage<T> pageQuery = new Page<>(page.getPageNo(), page.getPageSize());
        IPage<T> iPage = page(pageQuery);
        return PageUtils.pageConversion(iPage);
    }

    /**
     * mybatis plus page转换通用page
     * @param page
     * @param queryWrapper
     * @return
     */
    default com.swsc.solarverse.common.model.PageInfo<T> page(com.swsc.solarverse.common.model.PageInfo<Object> page, Wrapper<T> queryWrapper){
        Page<T> pageQuery = new Page<>(page.getPageNo(), page.getPageSize());
        IPage<T> iPage = page(pageQuery,queryWrapper);
        return PageUtils.pageConversion(iPage);
    }

    /**
     * mybatis plus page转换通用page
     * @param page
     * @param queryWrapper
     * @return
     */
    default com.swsc.solarverse.common.model.PageInfo<Map<String, Object>> pageMaps(com.swsc.solarverse.common.model.PageInfo<Object> page, Wrapper<T> queryWrapper) {
        IPage<Map<String, Object>> pageQuery = new Page<>(page.getPageNo(), page.getPageSize());
        IPage<Map<String, Object>> iPage = pageMaps(pageQuery, queryWrapper);
        return PageUtils.pageConversion(iPage);
    }

    /**
     * mybatis plus page转换通用page
     * @param page
     * @return
     */
    default com.swsc.solarverse.common.model.PageInfo<Map<String, Object>> pageMaps(com.swsc.solarverse.common.model.PageInfo<Object> page) {
        IPage<Map<String, Object>> pageQuery = new Page<>(page.getPageNo(), page.getPageSize());
        IPage<Map<String, Object>> iPage = pageMaps(pageQuery);
        return PageUtils.pageConversion(iPage);
    }

}
